﻿#if UNITY_EDITOR
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;

public class WZ_CalcLayersCount
{
    static List<int> layers = new List<int>();

    [MenuItem("Assets/统计layer种类数量")]
    public static void Calc()
    {
        layers = new List<int>();
        GameObject[] objs = Selection.gameObjects;
        for (int i = 0; i < objs.Length; i++)
        {
            _Calc(objs[i].transform);
        }

        layers.Sort();
        string ret = string.Empty;
        foreach (var item in layers)
        {
            ret += LayerMask.LayerToName(item) + "、";
        }
        Debug.LogFormat("layersCount:{0},layers:{1}", layers.Count, ret);
    }

    private static void _Calc(Transform obj)
    {
        if (layers.Contains(obj.gameObject.layer) == false)
        {
            layers.Add(obj.gameObject.layer);
        }

        foreach (Transform item in obj)
        {
            _Calc(item);
        }
    }
}
#endif